const fs = require('fs');
const join = require('path').join;
/*
@path 欲搜索的文件夹路径
@filename 欲搜索的文件名
@return Array
*/
module.exports = (path, filename) => {
	filename = filename.replace(/\//g,'\\');
	let a=[] ,anum=0;
	
	function getJsonFiles(jsonPath){
		let jsonFiles = [];
		function findJsonFile(path){
			let files = fs.readdirSync(path);
			files.forEach(function (item, index) {
				let fPath = join(path,item);
				let stat = fs.statSync(fPath);
				if(stat.isDirectory() === true) {
					findJsonFile(fPath);
				}
				if (stat.isFile() === true) { 
					jsonFiles.push(fPath);
				}
			});
		}
		findJsonFile(jsonPath);
		return jsonFiles;
	}
	let Filelist = getJsonFiles(path);
	for (let i=0 ;i<Filelist.length ;i++){
		if(String(Filelist[i]).includes(filename)){
			a[anum] = Filelist[i];
			anum++;
		}
	}
	return a
}